package com.seraphine.security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 描述: 基本配置
 * 作者: panhongtong
 * 创建时间: 2020-10-16 15:21
 **/
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    /**
     * 暂未整合用户权限
     */
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        auth.inMemoryAuthentication()
//                .withUser("learn")
//                .password(new BCryptPasswordEncoder().encode("123"))
//                .roles("admin")
//                .and()
//                .withUser("dafu")
//                .password(new BCryptPasswordEncoder().encode("123"))
//                .roles("user");
//    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // 设置一个表单登录
        http.csrf().disable().formLogin();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/anonymous/**");
    }
}
